import React from 'react'
import axios from 'axios'
import { Toast } from 'antd-mobile'
import {
  Form,
  Input,
  Button,

} from 'antd-mobile'
import { useNavigate } from 'react-router-dom'
function Index() {
  const tiao = useNavigate()
  const onFinish = async (values) => {
    const res = await axios.post('/api/login', values)
    console.log(res);
    const { code, data, message } = res.data
    if (code === 10000) {

      Toast.show({
        icon: 'success',
        content: message,
      })
      localStorage.setItem('token',data.accessToken)
      localStorage.setItem('userInfo',JSON.stringify(data.userInfo))
     tiao('/')
    } else {
      Toast.show({
        icon: 'fail',
        content: message,
      })
    }
  }
  return (
    <div>
      <Form
        layout='horizontal'
        onFinish={onFinish}
        footer={
          <Button block type='submit' color='primary' size='large'>
            提交
          </Button>
        }
      >

        <Form.Item
          name='username'
          label='账号'
          rules={[{ required: true, message: '姓名不能为空' }]}
        >
          <Input onChange={console.log} placeholder='请输入姓名' />
        </Form.Item>
        <Form.Item
          name='password'
          label='密码'
          rules={[{ required: true, message: '姓名不能为空' }]}
        >
          <Input onChange={console.log} placeholder='请输入姓名' />
        </Form.Item>




      </Form>
    </div>
  )
}

export default Index
